Skip to content

Ai features - #8

Merged
chengzi404-hash merged 9 commits into
masterfrom
ai-features
Jul 23, 2026
Merged

Ai features#8
chengzi404-hash merged 9 commits into
masterfrom
ai-features

Conversation

@chengzi404-hash

Copy link
Copy Markdown
Owner

Pull Request Description

Add Ai features.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Test Configuration:

  • OS: Windows 11 25H2
  • Python Version: 3.14

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

With issue: #7

chengzi404-byte and others added 6 commits July 22, 2026 18:44
新增 tests/editor/ (125 个测试) 覆盖 CodeEditor 全栈 — 不再只测模块
I/O,而是跑通实际的 UI 行为:

- test_lifecycle.py (18): 构造、组件装配、Python/JSON/YAML/XML/LOG
  语言切换、hooks 派发
- test_file_operations.py (18): 文件加载(按扩展名识别语言)、保存、
  autosave、错误处理、save → reload round-trip
- test_tabs.py (18): 新建/关闭/切换/关闭其它/关闭全部/循环、dirty
  跟踪、document 生命周期
- test_buffer.py (36): undo/redo、indent/outdent、toggle_comment、
  goto-line、find/replace、高亮、行闪烁、字体/制表宽、ghost-text、
  suggestion 弹窗、goto-definition、find_references、lookup_documentation
- test_settings.py (16): 字体/制表宽/主题/高亮/自动保存/补全开关
  的全局变更传播到 UI
- test_runner.py (13): Python 静态检查、runner 生命周期
- test_i18n.py (6): 语言切换重建菜单

测试用会话级 CodeEditor fixture,避开了 Python 3.14 + Tk 在
Windows 上多次创建/销毁时的 Tcl 库路径丢失问题。
settings 路径被 monkey-patch 指向私有 tmpdir,不会污染用户的
%APPDATA%/PythonEditor/settings.json。

顺带修 4 个 latent bug:

1. buffer.switch_language() — JSON/YAML/XML/LOG 的 suggestion 配置为
   None,旧代码直接 None() 会崩溃。改为优先 *_factory,回退时检查
   callable。
2. buffer.outdent() — 用绝对列号删除,越过行尾会吞掉换行符把两行
   拼在一起。改为每次从行首删除。
3. buffer._show_find_dialog() — 引用 dlg.window(不存在)而不是
   dlg._window,打开"查找"对话框崩溃。
4. tabs.init_first_document() — _next_seq 硬编码为 2,关闭最后一个
   tab 后 new_file() 会覆盖当前文档。改为按当前 seq 推进。

外加 3 个 core 修复:
- helpers.format_autosave_path — 默认格式 "{unix.seconds}" 触发
  str.format_map 的属性访问语义而 KeyError,改用 "{unix_seconds}"。
- app.CodeEditor 补齐 TabHost/RunnerHost 协议要求的 text_widget /
  editor_text / apply_highlight 属性(之前点"新建文件"或
  "Run check" 会因 AttributeError 崩溃)。

测试结果:521 passed(原 396 + 新增 125),ruff check /
ruff format --check 全通过。
@chengzi404-hash chengzi404-hash added the enhancement New feature or request label Jul 23, 2026
@github-actions github-actions Bot added bug Something isn't working documentation Improvements or additions to documentation labels Jul 23, 2026
新增的 tests/editor/ 需要创建 Tk 窗口,Ubuntu runner 没有现成的
DISPLAY,``tk.Tk()`` 会抛 TclError,导致整个 editor 测试套件崩溃。

两处改动:

1. ``.github/workflows/pytest.yml``:
   - apt 依赖里加上 ``xvfb``(除了 ``python3-tk``)
   - 在 Ubuntu runner 上用 ``xvfb-run -a`` 包住 pytest 调用;
     Windows runner 不变(Windows 的 Tk 用本地显示子系统,不需要 X11)

2. ``tests/editor/conftest.py``:
   - 加了 session-scope + autouse 的 ``_verify_tk_available`` fixture,
     启动时尝试 ``tk.Tk()`` 一次。如果环境完全没有 Tk(比如 macOS
     上的某些 CI 配置),整个 editor 测试会干净地 skip 而不会
     留下满屏 TclError。

``python -m pytest tests/`` 在 Windows 上仍 521 passed,行为不变。
@chengzi404-hash
chengzi404-hash merged commit 8d1ccaf into master Jul 23, 2026
5 checks passed
@chengzi404-hash
chengzi404-hash deleted the ai-features branch July 23, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

1 participant